﻿@{
    ViewData["Title"] = "Home Page";
}

<div class="text-center">
    <h1 class="display-4">Welcome to Task Scheduler</h1>
    <p>Easily manage your HTTP tasks.</p>
</div>

@if (TempData["SuccessMessage"] != null)
{
    <div class="alert alert-success alert-dismissible fade show" role="alert">
        @TempData["SuccessMessage"]
        <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
    </div>
}

@if (TempData["ErrorMessage"] != null)
{
    <div class="alert alert-danger alert-dismissible fade show" role="alert">
        @TempData["ErrorMessage"]
        <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
    </div>
}

<div class="text-center mt-5">
    <button type="button" class="btn btn-danger btn-lg" data-bs-toggle="modal" data-bs-target="#clearLogsModal">
        <i class="fas fa-trash-alt me-2"></i>Clear All Execution Logs
    </button>
    <p class="text-muted mt-2">This will delete all task execution history records</p>
</div>

<!-- Clear Logs Confirmation Modal -->
<div class="modal fade" id="clearLogsModal" tabindex="-1" aria-labelledby="clearLogsModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="clearLogsModalLabel">Confirm Clear Logs</h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <div class="modal-body">
                Are you sure you want to clear all execution logs? This action cannot be undone!
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
                <form asp-action="ClearAllLogs" method="post">
                    @Html.AntiForgeryToken()
                    <button type="submit" class="btn btn-danger">Confirm Clear</button>
                </form>
            </div>
        </div>
    </div>
</div>

@section Scripts {
    <script>
        // Clear TempData messages when modal is closed
        $('#clearLogsModal').on('hidden.bs.modal', function () {
            $('.alert').alert('close');
        });
    </script>
}